﻿using System.Xml;

using pt=System.UInt32;

namespace RDLC
{
   public class RDLBody
   {
      public pt Height;
      public RDLReportItems ReportItems = new RDLReportItems(); // Optional
      public int? Columns
      {
         get { return _Columns; }
         set
         {
            if(!_Columns.HasValue)
               _Columns = new int();
            _Columns = value;
         }
      }
      public int? _Columns;
      public pt? ColumnSpacing
      {
         get { return _ColumnSpacing; }
         set
         {
            if(!_ColumnSpacing.HasValue)
               _ColumnSpacing = new pt();
            _ColumnSpacing = value;
         }
      }
      public pt? _ColumnSpacing;

      public BodyStyle Style; // Optional

      public RDLBody(pt height)
      {
         Height = height;
      }

      public void Write(XmlTextWriter writer)
      {
         writer.WriteStartElement("Body");

         ReportItems.Write(writer);

         if(Columns.HasValue)
            writer.WriteElementString("Columns", Columns.Value.ToString());

         if(ColumnSpacing.HasValue)
            writer.WriteElementString("ColumnSpacing", ColumnSpacing.Value +"pt");

         writer.WriteElementString("Height", Height + "pt");

         if(Style != null)
            Style.Write(writer);

         writer.WriteEndElement(); // Body
      }
   }

   public class BodyStyle : RDLStyle
   {
      public RDLColor? BackgroundColor
      {
         get { return _BackgroundColor; }
         set
         {
            if(!_BackgroundColor.HasValue)
               _BackgroundColor = new RDLColor();
            _BackgroundColor = value;
         }
      }
      private RDLColor? _BackgroundColor;

      public RDLImage BackgroundImage;
      //Todo: Language is not implemented yet    

      public BodyStyle()
      {

      }

      public BodyStyle(RDLBorderColor borderColor, RDLBorderStyle borderStyle, RDLBorderWidth borderWidth)
         : base(borderColor, borderStyle, borderWidth)
      {
      }

      protected override void WriteDetails(XmlTextWriter writer)
      {
         if(BackgroundColor.HasValue)
            writer.WriteElementString("BackgroundColor", BackgroundColor.Value.ToString());

         if(BackgroundImage != null)
            BackgroundImage.Write(writer);
      }
   } 
}
